//写法一
#include <iostream>
using namespace std;

class BaseCalculator {
    public:
        int m_A;
        int m_B;
        // write your code here......
        //基类声明成虚函数
        virtual int getResult();
};

// 加法计算器类
class AddCalculator : public BaseCalculator {
    // write your code here......
public: 
    //子类virtual仍然可以保留
    virtual int getResult(){
        return m_A + m_B;
    }   
};

// 减法计算器类
class SubCalculator : public BaseCalculator {
    // write your code here......
public:
    virtual int getResult(){
        return m_A - m_B;
    }
};


int main() {

    BaseCalculator* cal = new AddCalculator;
    cal->m_A = 10;
    cal->m_B = 20;
    cout << cal->getResult() << endl;
    delete cal;

    cal = new SubCalculator;
    cal->m_A = 20;
    cal->m_B = 10;
    cout << cal->getResult() << endl;
    delete cal;

    return 0;
}

//写法二
#include <iostream>
using namespace std;

class BaseCalculator {
    public:
        int m_A;
        int m_B;
        // write your code here......
        //基类声明成纯虚函数
        virtual int getResult() = 0;
};

// 加法计算器类
class AddCalculator : public BaseCalculator {
    // write your code here......
public: 
    //子类virtual不可保留
    int getResult(){
        return m_A + m_B;
    }   
};

// 减法计算器类
class SubCalculator : public BaseCalculator {
    // write your code here......
public:
    int getResult(){
        return m_A - m_B;
    }
};


int main() {

    BaseCalculator* cal = new AddCalculator;
    cal->m_A = 10;
    cal->m_B = 20;
    cout << cal->getResult() << endl;
    delete cal;

    cal = new SubCalculator;
    cal->m_A = 20;
    cal->m_B = 10;
    cout << cal->getResult() << endl;
    delete cal;

    return 0;
}
/*
描述
完善下面的代码，使程序能够正常运行。要求 BaseCalculator 类中提供 getResult() 函数（无需实现），在 AddCalculator 类中实现两个成员相加（m_A + m_B），在 SubCalculator 类中实现两个成员相减（m_A - m_B）
输入描述：
无
输出描述：
程序已经给定输出*/